const fp = require('lodash/fp')
const { MayBe, Container } = require('./3-support.js')

// 练习1
let maybe = MayBe.of([5, 6, 1])
let ex1 = () => {
    maybe.map(fp.map(fp.add(1)))
}

// 练习2
let xs = Container.of(['do', 'ray', 'me', 'fa', 'so', 'la', 'ti', 'do'])
let ex2 = () => {
    xs.map(fp.first)
}

// 练习3
let safeProp = fp.curry(function(x, o) {
    return MayBe.of(o[x])
})
let user = { id: 2, name: 'Albert' }
let ex3 = () => {
    safeProp('name', user).map(fp.first)
}

//练习4
let ex4 = function(n) {
    return MayBe.of(n).map(parseInt)
}